import numpy as np
from matplotlib import pyplot as plt
from scipy.fft import fft, fftfreq


SAMPLE_RATE = 100  # Hertz
DURATION = 2  # Seconds

def generate_sine_wave(freq, sample_rate, duration):
    x = np.linspace(0, duration, sample_rate * duration, endpoint=False)
    print(len(x))
    print(x)
    frequencies = x * freq
    # 2pi because np.sin takes radians
    # 2*pi*f*n*T
    y = np.sin((2 * np.pi) * frequencies)
    print(y)
    return x, y

# Generate a 2 hertz sine wave that lasts for 5 seconds
x, y = generate_sine_wave(2, SAMPLE_RATE, DURATION)
# plt.figure(1)
# plt.plot(x, y)
# plt.show()

# _, nice_tone = generate_sine_wave(400, SAMPLE_RATE, DURATION)
# _, noise_tone = generate_sine_wave(4000, SAMPLE_RATE, DURATION)
# noise_tone = noise_tone * 0.3

# mixed_tone = nice_tone + noise_tone

# normalized_tone = np.int16((mixed_tone / mixed_tone.max()) * 32767)
# plt.figure(2)
# plt.plot(normalized_tone[:1000])
# plt.show()


# # Number of samples in normalized_tone
# N = SAMPLE_RATE * DURATION

# yf = fft(normalized_tone)
# xf = fftfreq(N, 1 / SAMPLE_RATE)

# plt.figure(3)
# plt.plot(xf, np.abs(yf))
# plt.show()

xn_t_1 = np.array([1,-1,0,1,-1,0,1,-1])


yn_t_1 = fft(xn_t_1, len(xn_t_1))
#xf_t_1 = fftfreq(len(xn_t_1), 1/)
print(yn_t_1)
for i in range(len(yn_t_1)):
	print(yn_t_1[i])


[ 0.        +0.j         -0.12132034+0.29289322j -1.        +1.j
  4.12132034-1.70710678j  2.        +0.j          4.12132034+1.70710678j
 -1.        -1.j         -0.12132034-0.29289322j]
